package com.example.model;

public class Resp<T> {

    private int code;
    private String msg;//我们服务端返回的数据
    private T data;

    private Resp(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private Resp(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> Resp success(T data) {
        return new Resp(200, "success", data);
    }

    public static <T> Resp error(AppExceptioncodeMsg appExceptioncodeMsg) {
        Resp resp = new Resp(appExceptioncodeMsg.getCode(),
                appExceptioncodeMsg.getMsg(), null);
        return resp;
    }

    public static <T> Resp error(int code, String msg) {
        return new Resp(code, msg, null);
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}
